package edu.hawaii.duedates;

import static org.junit.Assert.assertEquals;
//import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import org.junit.Test;


/**
 * Some tests to check the DueDates class.
 * 
 * @author Arthur Shum and Erin Kim
 */
public class TestDueDates {
  
  /**
   * Test that the method throws an exception if there are no arguments.
   * 
   * @throws Exception If an error occurs during the test.
   */
  @Test (expected = Exception.class)
  public void testNoArgs() throws Exception {
    DueDates duedates = new DueDates();
    String[] args = new String[0];
    duedates.argparser(args);
  }
  
  /**
   * Test that the method throws an exception if there is no -console or -email in the arguments.
   * 
   * @throws Exception If an error occurs during the test.
   */
  @Test (expected = Exception.class)
  public void testArgsNoConsoleOrEmail() throws Exception {
    DueDates duedates = new DueDates();    
    String[] args = { "-uhm", "1234", "12" };
    duedates.argparser(args);
    fail("Should't get here");
  }
  
  /**
   * Test that the method throws an exception if there is no -uhm or -hsl in the arguments.
   * 
   * @throws Exception If an error occurs during the test.
   */
  @Test (expected = Exception.class)
  public void testArgsNoUhmOrHsl() throws Exception {
    DueDates duedates = new DueDates();    
    String[] args = { "-console" };
    duedates.argparser(args);
    fail("Should't get here");
  }
  
  /**
   * Test that the method assigns the expected values to the instance variables.
   * 
   * @throws Exception If an error occurs during the test.
   */
  @Test
  public void testPopulateArgs() throws Exception {
    DueDates duedates = new DueDates();
    String[] args = { "-uhm", "uhid", "lastname", "-email", "email@address.com", "smtp.server.com",
        "-within", "30", "-verbose", "-wakeup", "1", "-sort", "duedate" };
    duedates.argparser(args);
    // false (the default value) because argparser() uses BooleanHolder
    assertEquals("Should be false", false, duedates.useConsole);
    assertEquals("email address", "email@address.com", duedates.emailAddr);
    assertEquals("smtp server", "smtp.server.com", duedates.smtpHost);
    assertEquals("banner id", "uhid", duedates.bannerId);
    assertEquals("last name", "lastname", duedates.lastName);
    // null because argparser() uses String[] (can't use StringHolder)
    assertNull("barcode", duedates.barcode);
    assertNull("pin", duedates.pin);
    assertEquals("sort", "duedate", duedates.sortBy);
    assertEquals("within", 30, duedates.withinDays);
    assertEquals("wakeup", 1000 * 60 * 60 * 24, duedates.wakeupInMs);
    assertTrue("verbose", duedates.isVerbose);
    assertTrue("getuhm", duedates.getUhm);
    assertEquals("gethsl", false, duedates.getHsl);
    assertTrue("argsok", duedates.argsOk);
  }

}
